/* eslint-disable @typescript-eslint/no-unused-vars */ // DO NOT EDIT THIS FILE. AUTO-GENERATED BY mobiletto-orm-typedef-gen import { H3Event } from "h3"; import { AccountType, AccountTypeDef } from "yuebing-model"; import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef"; export default defineEventHandler(async (event: H3Event) => { return await filterErrors(event, "account.update", async (event: H3Event) => { return await requireAccountObject(event, "account.update", async (event: H3Event, session, account) => { const accountRepo = accountRepository(); const id = event?.context?.params?.id; if (!id) throw notFound(accountRepo.typeDef.idFieldName()); const obj: AccountType = await readBody(event); if (!obj) { throw badRequest(); } if (AccountTypeDef.id(obj) !== id) { const errs: MobilettoOrmValidationErrors = {}; errs[accountRepo.typeDef.idFieldName()] = ["mismatch"]; throw validationError(errs); } else { if (!account.admin && obj.account && obj.account !== session.account) throw forbidden(); if (typeof AccountTypeDef.apiConfig.update?.validate === "function") { const validated = await AccountTypeDef.apiConfig.update.validate(account, obj); if (validated === true || (typeof validated === "object" && Object.keys(validated).length === 0)) { // successfully validated } else if (typeof validated === "object" && Object.keys(validated).length > 0) { throw validationError(validated); } else { throw validationError({global: ["validation"]}); } } return await accountRepo.update(obj); } }); }); });